package cn.mntool.es.config;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.Inet4Address;
import java.net.UnknownHostException;

/**
 * describe: Es配置
 *
 * @author lianying
 * @date 2020/07/26
 */
@Configuration
public class EsConfig {

    @Bean
    public PreBuiltTransportClient client() throws UnknownHostException {
        TransportAddress transportAddress1=new InetSocketTransportAddress(Inet4Address.getByName("192.168.100.100"),9300);
//        TransportAddress transportAddress2=new InetSocketTransportAddress(Inet4Address.getByName("192.168.100.100"),9301);
//        TransportAddress transportAddress3=new InetSocketTransportAddress(Inet4Address.getByName("192.168.100.100"),9302);
        Settings settings= Settings.builder().put("cluster.name","wali").build();
        PreBuiltTransportClient client=new PreBuiltTransportClient(settings);
        client.addTransportAddresses(transportAddress1);
        return client;
    }
}
